//
// Created by robot on 20-7-10.
//

#include "TCPIPRobot.hpp"
#define MAX_RECEDATA 24
TCPIPRobot::TCPIPRobot()
{

}
TCPIPRobot::~TCPIPRobot()
{
}

int TCPIPRobot::connect(const QString IP, int port)
{
    sock_cli = socket(AF_INET,SOCK_STREAM, 0);

    struct sockaddr_in servaddr01;
    memset(&servaddr01, 0, sizeof(servaddr01));
    servaddr01.sin_family = AF_INET;//tech5
    servaddr01.sin_port = htons(port);                        //server port
    servaddr01.sin_addr.s_addr = inet_addr(IP.toLatin1().data());    //server ip
    if (::connect(sock_cli, (struct sockaddr *)&servaddr01, sizeof(servaddr01)) < 0) {
        perror("connect");
        return -1;
    }

    return 0;
}

long long TCPIPRobot::currentTime(void)
{
    struct timespec time_m ={0,0};

    clock_gettime(CLOCK_REALTIME, &time_m);
    return static_cast<long long>(time_m.tv_sec*1000+time_m.tv_nsec/1000000);
}

void TCPIPRobot::receData()
{
    int  cli_index;
    while(!_isstop){
    }
}

void TCPIPRobot::receData2()
{
    int  cli_index;
    while(!_isstop){
    }
}
int TCPIPRobot::get_socket()
{
    return sock_cli;
}

void TCPIPRobot::isstop(const bool& isstop)
{
    _isstop=isstop;
}
